#pragma once
#include <vector>
#include <string>
#include "..\\SGD Wrappers\SGD_Geometry.h"
#include "..\\SGD Wrappers\\SGD_Handle.h"
#include "MovingObject.h"

class GameObject;
class Projectile;

namespace SGD
{
	class GraphicsManager;
}

struct Tile
{
	bool			isCollidable;
	bool			activeRender;
	bool			triggered = false;
	bool			turnedoff = false;
	SGD::Point		tsPos;
	SGD::Rectangle	mapPos;
	std::string		event;
	std::string		type;
};

struct Layer
{
	std::vector<Tile>		tiles;
};

class Map
{
	SGD::Size				tileSize;
	SGD::Size				mapSize;
	SGD::Size				tilesetSize;
	int						numLayers;
	SGD::Rectangle			collisionRect;
	std::vector<Layer>		layers;
	SGD::GraphicsManager*	graphics = nullptr;
	SGD::HTexture			tileset = SGD::INVALID_HANDLE;

public:
	Map		(void);
	~Map	(void) = default;

	//Mutators
	void	SetTileHeight	(const float height)	{ tileSize.height = height; }
	void	SetTileWidth	(const float width)	{ tileSize.width = width; }
	void	SetMapRows		(const float rows)	{ mapSize.height = rows; }
	void	SetMapCols		(const float cols)	{ mapSize.width = cols; }
	void	SetTilesetRows	(const float rows)	{ tilesetSize.height = rows; }
	void	SetTilesetCols	(const float cols)	{ tilesetSize.width = cols; }
	void	SetNumLayers	(const int num)		{ numLayers = num; }
	void	TurnOffTile		(SGD::Point point);

	//Accessors
	float				GetTileHeight	(void)	const	{ return tileSize.height; }
	float				GetTileWidth	(void)	const	{ return tileSize.width; }
	float				GetMapHeight	(void)	const	{ return mapSize.height * tileSize.height; }
	float				GetMapWidth		(void)	const	{ return mapSize.width * tileSize.width; }
	float				GetMapRows		(void)	const	{ return mapSize.height; }
	float				GetMapCols		(void)	const	{ return mapSize.width; }
	float				GetTilesetRows	(void)	const	{ return tilesetSize.height; }
	float				GetTilesetCols	(void)	const	{ return tilesetSize.width; }
	int					GetNumLayers	(void)	const	{ return numLayers; }
	std::vector<Layer>&	GetLayers		(void)			{ return layers; }
	Layer&				GetLayer		(int index)		{ return layers[index]; }

	void	Render						(SGD::Point camera, float screenWidth, float screenHeight);
	void	CheckCollision			(GameObject* object);
	bool	CheckCollision			(SGD::Point position);
	void	Start					(void);
	void	Spawn					(void);
	void	BulletDeletion			(Projectile* bullet);

	//Resource management
	void	LoadTileSet(const char* path);
	void	UnloadTileSet(void);
};

